package intermediate

fun main() {
    println(testadd(5))
    println(fib(10))
    println(test1(5))
}

fun testadd(n: Int): Int {
    if (n == 1) return 1
    return n * testadd(n - 1)
}
fun fib(n: Int): Int{
    if (n<=2) return 1
    return fib(n-1)+fib(n-2)
}
//tailrec关键字
tailrec fun test1(n: Int,sum: Int=0): Int{
    if(n<=0)return sum
    return test1(n-1,sum+n)
}
